<!-- 购物车 -->
<template>
  <view class="container">
    <aster-empty
      v-if="!isLogin"
      ref="asterEmptyRef"
      e-style="round"
      e-type="cart"
      tip="登录后才能看到商品哦~"
      btn-tip="立即登录"
      height="50vh"
      :auto="false"
      @goto="tologin"
    />
    <aster-empty
      v-else-if="empty"
      ref="asterEmptyRef"
      e-style="round"
      e-type="cart"
      tip="目前没有添加商品哦~"
      btnTip="去首页逛逛"
      height="50vh"
    />
    <view v-else>
      <!-- 顶部操作按钮 -->
      <view>1</view>
      <!-- 中间购物列表 -->
      <view>2</view>
      <!-- 底部操作按钮 -->
      <view>3</view>
    </view>
  </view>
</template>

<script setup lang="ts">
  import { ref } from 'vue';
  import AsterEmpty from '@/components/empty/aster-empty.vue';
  import { jumpLogin } from '@/utils/router/interceptor';
  import { CART_PAGE } from '@/enums/routerEnum';
  import { onLoad, onShow } from '@dcloudio/uni-app';
  import { useAuthStore } from '@/store/modules/auth';
  import { getCartList } from '@/services/api/tabbar/cart';
  import { CartModel } from '@/services/model/CartModel';
  import { isEmpty } from '@/utils/is';

  // 注册子组件
  const asterEmptyRef = ref();
  // 是否已登录
  const isLogin = ref<boolean>(true);
  // 购物车是否为空
  const empty = ref<boolean>(true);
  // 购物车列表
  const cartList = ref<Array<CartModel>>([]);

  // 跳转登录页
  const tologin = () => {
    jumpLogin(CART_PAGE);
  };

  // 加载数据
  const loadData = () => {
    getCartList().then(({ data }) => {
      cartList.value = data.data;
      empty.value = isEmpty(data.data);
    });
  };

  onLoad(() => {
    console.log('load');
  });

  onShow(() => {
    // const authStore = useAuthStore();
    // isLogin.value = authStore.isLogin;
    loadData();
  });
</script>

<style scoped lang="scss"></style>
